home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Buffers / BufferOf.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  1.3 KB  |  59 lines  |  [TEXT/CWIE]

  1. // BufferOf.h
  2.  
  3. #ifndef BufferOf_h
  4. #define BufferOf_h
  5.  
  6. #ifndef ArrayOf_h
  7. #include "ArrayOf.h"
  8. #endif
  9.  
  10. template < class Element > class ConstBufferOf;
  11.  
  12. template < class Element >
  13. class BufferOf
  14.   {
  15.     typedef ArrayOf<Element> ArrayType;
  16.     typedef ConstArrayOf<Element> ConstArrayType;
  17.  
  18.     typedef BufferOf<Element> BufferType;
  19.     typedef ConstBufferOf<Element> ConstBufferType;
  20.     
  21.     private:
  22.         ArrayType space;
  23.         uint32 mark;
  24.     
  25.         // not implemented:
  26.             BufferOf( const BufferType& );
  27.             void operator=( const BufferType& );
  28.         
  29.     public:
  30.         BufferOf( ArrayType );
  31.         
  32.         void Reset()                            { mark = 0; }
  33.         void Reset( ArrayType );
  34.  
  35.         inline void AdvanceMark( uint32 amount );
  36.         
  37.         ConstArrayType Used() const        { return space.Head( mark ); }
  38.         ArrayType Unused() const            { return space.Tail( mark ); }
  39.         
  40.         uint32 TotalLength() const            { return space.Length(); }
  41.         uint32 UsedLength() const            { return mark; }
  42.         uint32 UnusedLength() const        { return space.Length() - mark; }
  43.         
  44.         bool IsEmpty() const                    { return mark == 0; }
  45.         bool IsFull() const                    { return mark >= space.Length(); }
  46.         
  47.         void operator<<( ConstArrayType );
  48.         void operator<<( ConstBufferType& );
  49.   };
  50.  
  51. template < class Element >
  52. inline void BufferOf<Element>::AdvanceMark( uint32 amount )
  53.   {
  54.     Assert( amount <= UnusedLength() );
  55.     mark += amount;
  56.   }
  57.  
  58. #endif
  59.